import { addComDao, getComByPageDao,delComDao,updateComDao, getComByIdsByPageDao} from "../Dao/commentDao.js"
import { findUserByIdDao } from "../Dao/userDao.js";


export const addComServ =async (obj) =>{
    await addComDao();
    return {
        code:0,
        msg:"add ok"
    }
}

export const delComServ =async (id) =>{
    await delComDao(id);
    return {
        code:0,
        msg:"del ok"
    }
}

export const updateComServ =async (id,obj) =>{
    await updateComDao(id,obj);
    return {
        code:0,
        msg:"update ok"
    }
}

export const getComByPageServ =async (page,size) =>{
    const data = await getComByPageDao(page,size);
    data.list =await Promise.all(data.list.map(async item =>{
        const obj = item.toObject()
        obj.user =await findUserByIdDao(obj.userId);
        return obj
    }))
    return {
        code:0,
        data
    } 
}

export const getComByIdsPageServ =async (ids,page,size) =>{
    const data = await  getComByIdsByPageDao(ids,page,size)
    data.list =await Promise.all(data.list.map(async item =>{
        const obj = item.toObject();
        obj.user =await findUserByIdDao(obj.userId)
        return obj
    }))
    return {
        code:0,
        data
    }
}




















